package com.zhangxiaofanfan.hotcode.fourth.third;

/**
 * TODO
 *
 * @author zhangxiaofanfan
 * @date 2024-05-24 17:07:19
 */
public class HotCode017 {
    public static void main(String[] args) {
        int[] nums = {1,2,3,4};
        HotCode017 hotCode017 = new HotCode017();
        System.out.println(hotCode017.firstMissingPositive(nums));
    }

    public int firstMissingPositive(int[] nums) {
        boolean[] dp = new boolean[nums.length + 1];
        for (int num : nums) {
            if (num >= 1 && num <= nums.length + 1) {
                dp[num - 1] = true;
            }
        }
        for (int i = 0; i < dp.length; i++) {
            if (!dp[i]) {
                return i + 1;
            }
        }
        return dp.length;
    }
}
